;;==========================================================================
;; Prototype1: bootsect.asm file
;;
;; made based on different sources
;;
;;==========================================================================
;;
[BITS 16]       ; 16-bit intructions for Real mode

[ORG 0x7C00]    ; boot sector loading into memory location 0x7C00

reset:
        mov ah, 0               
        int 13h                 
        or ah, ah               
        jnz reset			    

        mov ax, 0
        mov es, ax
        mov bx, 0x1000          

        mov ah, 02h             
        mov al, 02h             
        mov ch, 0               
        mov cl, 02h             
        mov dh, 0               
        int 13h                 
        or ah, ah               
        jnz reset               

        cli                     

        xor ax, ax
        mov ds, ax              
        
;;        
;; GDT Global Descriptor Table
;;
        lgdt [gdt_desc]         

        mov eax, cr0            
        or eax, 1               
        mov cr0, eax            

        jmp 08h:clear_pipe      


[BITS 32]                       
clear_pipe:
        mov ax, 10h            
        mov ds, ax              
        mov ss, ax              
        mov esp, 090000h        

        jmp 08h:01000h          


gdt:                    

gdt_null:               
        dd 0
        dd 0

gdt_code:               
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:               ; Data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end:                ; Used to calculate the size of the GDT



gdt_desc:                       ; The GDT descriptor
        dw gdt_end - gdt - 1    ; Limit (size)
        dd gdt                  ; Address of the GDT




times 510-($-$$) db 0           ;

        dw 0AA55h               ; Boot sector signature
